package com.example.crm.dao.impl;

import com.example.crm.dao.IUserDAO;
import com.example.tools.DBUtils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class UserDAOImpl implements IUserDAO {
    @Override
    public boolean findByUsernamePassword(String username, String password) {
        //连接数据库
        Connection con= null;
        try {
            con = DBUtils.getConnection();

            // 得到查询对象
            Statement st=con.createStatement();
            // 执行sql语句
            String sql="select * from user where username='"+username+"'and password='"+password+"';";
            System.out.println(sql);
            ResultSet rs=st.executeQuery(sql);
            // 得到结果集
            // 返回结果
            if(rs.next()){
                return true;
            }else {
                return false;
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return false;
    }
}
